<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.is.model.ParamCourse"%>
<%@page import="com.is.model.User"%>
<%@page import="com.is.control.ParamCourseControl"%>
<%@page import="com.is.control.ParamStuyearTypeControl"%>
<%@page import="com.is.model.ParamStuyearType"%>
<%@page import="com.is.control.ParamStuyearControl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="/InterStu/resources/image/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../resources/css/all.css" />
<link rel="stylesheet" type="text/css" href="../../resources/css/course.css" />
<link href="../../resources/css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../resources/js/jquery-1.8.1.js"></script>
<script type="text/javascript" src="../../resources/js/jquery.artDialog.js"></script>
<script type="text/javascript" src="../../resources/js/iframeTools.js"></script>
<script type="text/javascript">
	$(function(){
		(function (config) {
		    config['lock'] = false;
		    config['fixed'] = true;
		    config['okVal'] = '确定';
		    config['cancelVal'] = '取消';
			config['skin'] = 'default';
			config['drag'] = 'true';
		    // [more..]
		})(art.dialog.defaults);	
		var block = $("#magic_block");
		if($(".active a").position()){
			block.css("top",$(".active a").position().top+10)
			.data("oriTop",$(".active a").position().top)
		}
		$(".nav ul li").find("a").hover(
			function(){
				var $this = $(this);
				var newTop = $this.position().top;
				block.stop().animate({
					top:newTop+10
				})
			},
			function(){
				block.stop().animate({
					top:block.data("oriTop")+10
				})
			}
		)
		$('#addForm').hide();
		$('#updateForm').hide();
		$('#addCourse').click(function() {
			$.dialog({
				title:"添加课程",
				content:document.getElementById("addForm")
			})
		});
		$('#submitAdd').click(function() {
			var reg = /^\s*$/;
			if(!$("[name='courseName']").val().match(reg)){
				var addterm;
				for(var i=0;i<$("[name='gradeAdd']").size();i++){
					if($("[name='gradeAdd']").eq(i).attr("checked")){
						addterm = $("[name='gradeAdd']").eq(i).val();
					}
				}
				$.ajax({
					type:"get",
					cache:false,
					url:"course_add.jsp",
					dataType:"json",
					data:{
					courseName:$('#courseName').val(),
					courseNameEn:$('#courseNameEn').val(),
	                grade:addterm
					},
					success:function(data){
						if(data.status==1){
							window.location.reload();
							}else{
								alert("添加失败");
								}
						}
					})
				}
			});
		$('[name=update]').click(function(){
			$.dialog({
				title:'修改课程',
				content: document.getElementById("updateForm")
			})
			$('#courseId').val($(this).prev().val());
			$('#courseName_up').val($(this).parent().prev().prev().prev().text());
			$('#courseNameEn_up').val($(this).parent().prev().prev().text());
			var chooseterm = $(this).next().val();
			for(var i=0;i<$("[name='grade_up']").size();i++){
				if($("[name='grade_up']").eq(i).val() == chooseterm){
					$("[name='grade_up']").eq(i).attr("checked",true);
				} else{
					$("[name='grade_up']").eq(i).attr("checked",false);
				}
			}
		});
		$('#submitUpdate').click(function(){
		       var grade=document.getElementsByName("grade_up");
			   var grade_up;
			   for(var i=0;i<grade.length;i++)
			   {
			     if(grade.item(i).checked){
			         grade_up=grade.item(i).getAttribute("value");  
			     break;
			   }
			   }
			$.ajax({
				type:"get",
				cache:false,
				url:"course_update.jsp",
				dataType:"json",
				data:{
				    courseId:$('#courseId').val(),
				    courseName_up:$('#courseName_up').val(),
				    courseNameEn_up:$('#courseNameEn_up').val(),
				    grade_up:grade_up
				},
				
				success:function(data){
					if(data.status==1){
						window.location.reload();
						}else{
							alert("修改失败");
							}
					}
				})
			});
		$('[name=delete]').click(function(){
			var  isConfirm = confirm("确认删除？");
			if(isConfirm==true){
				$.ajax({
					type:"get",
					cache:false,
					url:"course_delete.jsp",
					dataType:"json",
					data:{
						courseId:$(this).prev().prev().val()
						},
						success:function(data){
							if(data.status==1){
								window.location.reload();
								}else{
									alert("删除失败");
									}
							}
					})
				} 
			})
			var h = $(".right").height();
			$(".left").height(h);
			$(".update").click(function(){
				$.dialog.open("/InterStu/update_info.jsp",{width:460,height:400,title:"个人信息"});
			})
			$('img').error(function(){
				this.src = "/InterStu/resources/image/man.GIF";
			})
	})
</script>
<title>留学生预科班</title>
</head>
<% 
	User cu =(User)session.getAttribute("user"); 
%>
<body>
<div class="header">
	<div class="title pr">
    	<a href="javascript:void(0);"><span class="update pa" onclick="return update();">个人信息</span></a>
        <span class="logout pa"><a class="hide" href="/InterStu/login/logout.jsp">退出</a></span>
    </div>
</div>
<div class="main">
	<div class="left"> 
	   <div class="infomation">
			<div class="photo">
			<%
			String picUrl = cu.getPicUrl();
			%>
				<img width='60' height="60" src = "<%=picUrl %>"  />
			</div>
			<div class="welcome">
				<%=cu.getName() %>,<br/>
				欢迎您使用！
			</div>
		</div>  	   	
    	<div class="nav">
        	<ul>	
            	<li class="pa" id="magic_block"></li>
                <li class="active"><a href="/InterStu/pages/stuyear/stuyear_start.jsp">新学期设置</a></li>
                <li><a href="/InterStu/pages/users/user_all.jsp">用户管理</a></li>
                <li><a href="/InterStu/pages/students/student_add.jsp">学生管理</a></li>
                <li><a href="/InterStu/pages/dictation/dictation_add.jsp">学生考核</a></li>
                <li><a href="/InterStu/pages/assess/teacher_assess.jsp">教职人员管理</a></li>
            </ul>
        </div>
    </div>
    <div class="right">
    	<div class='r1'>
    	<table class="term tab">
    <tr>
    	<td>
    		<a href="/InterStu/pages/stuyear/stuyear_start.jsp">学期开关</a>
		</td>
		<td>
			<a href="../paramClass/param_class_add.jsp">班级设置</a>
		</td>
		<td>
			<a class="current" href="/InterStu/pages/paramCourse/course.jsp">添加课程</a> 
		</td>
    </tr>
    </table>
    	<table class="table">
    	<caption>已添加课程</caption>
    		<thead>
			<tr>
			<th>课程</th><th>CourseType</th><th>上课时间</th><th>操作</th></tr>
			</thead>
			<tbody>
			<%
	           List<ParamCourse> pcs = ParamCourseControl.getAllCoursesByType("");
	           for(ParamCourse pc:pcs){
	        	   %>
	        	   <tr>
	        	   <td><%=pc.getCourseName() %></td><td><%=pc.getCourseNameEn() %></td>
	        	   <td><%=ParamStuyearTypeControl.getTypeName(pc.getTypeId())%></td>
	        	   <td><input type="hidden" value="<%=pc.getId() %>"/>
	        	   <a href="javascript:void(0);" name="update">修改</a>
	        	   <input type="hidden" value="<%=pc.getTypeId()%>"/>
	        	   <a href="javascript:void(0);" name="delete" style="display: none;">删除</a></td>
	        	   </tr>
	        	   <%
	           }
			%>
			</tbody>
		</table>
		<br/>
		<input type="button" value="添加课程" id="addCourse"/>
		<input type="button" value="进入课程分配"  onclick="window.location.href='../courseClass/set.jsp'"/>
		
		<form id="addForm" autocomplete='off'>
			<p><label>课程名：</label><input class="txt"  type="text"  name="courseName" id="courseName"/></p>
			<p><label>课程名English：</label><input class="txt" type="text"  name="courseNameEn" id="courseNameEn"/></p>
			<p><label>上课时间：</label>
			<%
				List<ParamStuyearType> stuyearTypes = ParamStuyearTypeControl.getAllStuyearTypes();
				System.out.print(ParamStuyearControl.getCurrentStuyear().getTypeId());
				for(ParamStuyearType stuyearType:stuyearTypes){
			%>
			<input type="radio" name="gradeAdd"  value="<%=stuyearType.getId() %>" <%if(ParamStuyearControl.getCurrentStuyear().getTypeId()==stuyearType.getId()) out.print("checked='checked'"); %>/><%=stuyearType.getTypeName() %>
			<%} %>
			</p>
			<p><input type="button" value="提交" id="submitAdd"/></p>
		</form>
		
		<form id="updateForm">
			<p><label>课程</label><input class="txt"  type="text" name="courseName_up" id="courseName_up" value=""/></p>
			<p><label>CourseType</label><input class="txt"  type="text" name="courseNameEn_up" id="courseNameEn_up" value=""/></p>
			<p><label>上课时间：</label>
			<%
			//List<ParamStuyearType> stuyearTypes2 = ParamStuyearTypeControl.getAllStuyearTypes();
			for(ParamStuyearType stuyearType:stuyearTypes){
			%>
			<input type="radio" name="grade_up" id="grade_up1" value="<%=stuyearType.getId() %>"/><%=stuyearType.getTypeName() %>
			<%} %>
			</p>
			<p><input type="hidden" name="courseId" id="courseId" />
			<input type="button" id="submitUpdate" value="提交"/></p>
		</form>
		</div>
    </div>
</div>
<div class="footer">
	<p>版权所有：东北师范大学留学生预科部&nbsp;&nbsp;  蓝旭工作室开发</p>
</div>
</body>
</html>
